#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <colors>
#include <cstrike>
#include <PowerupsX>

#define PREFIX "{olive}PowerupsX {default}>{green} "

new AbilityVamp;

new g_iBeamSprite;
new g_iHaloSprite;

public Plugin:myinfo= 
{
	name="PowerupsXL Vamparism",
	author="Skydive",
	description="Powerups X Vamparism Ability",
	version="1.0",
	url=""
};

public OnMapStart()
{
	g_iBeamSprite = PrecacheModel("materials/sprites/laser.vmt");
	g_iHaloSprite = PrecacheModel("materials/sprites/halo01.vmt");
}

public OnPluginStart()
{
	NativeIncStart();
	
	AbilityVamp = PX_RegisterAbility("AbilityVamparism");
	PX_SetAbilityName(AbilityVamp,"Vamparism");
	PX_SetAbilityDescription(AbilityVamp,"Max. 4: Leech Armor");
	PX_SetAbilityUsage(AbilityVamp,"Leech Health.");
	PX_AbilityUseColor(AbilityVamp,true);
	PX_SetAbilityColor(AbilityVamp,255,0,0,255);
	PX_SetAbilityMaxLevel(AbilityVamp,4);
	
	HookEvent("player_hurt",Event_PlayerHurt);
}

public Action:Event_PlayerHurt(Handle:event, const String:name[],bool:dontBroadcast)
{
	new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	new Level = PX_GetLevel(attacker, PX_GetAbility(attacker));
	if(PX_GetAbility(attacker) == AbilityVamp)
	{
		new victim = GetClientOfUserId(GetEventInt(event, "userid"));
		new dhealth = GetEventInt(event, "dmg_health");
		new darmor = GetEventInt(event, "dmg_armor");
		
		if (dhealth > 0)
		{	
			SetEntityHealth(attacker,GetClientHealth(attacker)+(Level+1));
			new color[4]={ 255,0,0,255 };
			new Float:victimloc[3],Float:attackerloc[3];
			GetClientAbsOrigin(victim,victimloc);
			GetClientEyePosition(attacker,attackerloc);
			attackerloc[2] += 10;
			victimloc[2] += 10;
			TE_SetupBeamPoints(attackerloc,victimloc,g_iBeamSprite,g_iHaloSprite,0,66,0.5,10.0,10.0,0,10.0,color,10);
			TE_SendToAll();
		}	
		if (darmor > 0 && Level >= 4)
		{
			SetEntProp(attacker, Prop_Send, "m_ArmorValue",GetClientArmor(attacker)+(Level+1));
			new color[4]={ 255,255,0,255 };
			new Float:victimloc[3],Float:attackerloc[3];
			GetClientAbsOrigin(victim,victimloc);
			GetClientEyePosition(attacker,attackerloc);
			attackerloc[2] -= 1;
			TE_SetupBeamPoints(attackerloc,victimloc,g_iBeamSprite,g_iHaloSprite,0,66,0.5,20.0,20.0,0,10.0,color,10);
			TE_SendToAll();
		}
	}
}